<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
		  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{/base/login/assets/css/reset.css}"/>
<link rel="stylesheet" th:href="@{/base/login/assets/css/supersized.css}"/>
<link rel="stylesheet" th:href="@{/base/login/assets/css/style.css}"/>   
<link rel="stylesheet" type="text/css" th:href="@{/base/login/css/styles.css}"/>
<title>login</title>
    <style>
        body {
            margin: 50px 0;
            text-align: center;
        }
        .inp {
            border: 1px solid gray;
            padding: 0 10px;
            width: 200px;
            height: 30px;
            font-size: 18px;
        }
        .btn {
            border: 1px solid gray;
            width: 100px;
            height: 30px;
            font-size: 18px;
            cursor: pointer;
        }
        #embed-captcha {
            width: 300px;
            margin: 0 auto;
        }
        .show {
            display: block;
        }
        .hide {
            display: none;
        }
        #notice {
            color: red;
        }
        /* 以下遮罩层为demo.用户可自行设计实现 */
        #mask {
            display: none;
            position: fixed;
            text-align: center;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            overflow: auto;
        }
        /* 可自行设计实现captcha的位置大小 */
        .popup-mobile {
            position: relative;
        }
        #popup-captcha-mobile {
            position: fixed;
            display: none;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            -webkit-transform: translate(-50%, -50%);
            z-index: 9999;
        }
    </style>
</head>

<body>
        <div class="page-container">	           
		<div class="wrapper">	
			<div class="container">
				<strong><span style="font-weight: bold;font-size: 25px;">登  录</span></strong> 
				<form class="form layui-form"  method="post" id="login_form">
					<input type="text" id="username" lay-verify="required"  name="username" placeholder="Username">
					<input type="password" lay-verify="required" id="password"  name="password"  placeholder="Password">
					 <div id="popup-captcha"></div>
					<button type="submit"  lay-submit lay-filter="login" id="login-button">Login</button>
				</form>
			</div>
	  </div>
        </div>
         <script type="text/javascript" th:src="@{/base/login/js/jquery-2.1.1.min.js}"></script>
        <!-- Javascript -->
        <script th:src="@{/base/layui/layui.js}"></script>
        <script th:src="@{/base/login/assets/js/jquery-1.8.2.min.js}"></script>
        <script th:src="@{/base/login/assets/js/supersized.3.2.7.min.js}"></script>
        <script th:src="@{/base/login/assets/js/supersized-init.js}"></script>
        <script th:src="@{/base/login/assets/js/scripts.js}"></script>
        <script th:src="@{/base/js/gt.js}"></script>
        <script type="text/javascript" th:src="@{/base/js/jquery.easyui.min.js}"></script>
</body>
<script type="text/javascript">
$(function () {
	if (window.parent != window){
		   window.top.location.href = location.href;
		  }
})
layui.use(['layer', 'form'], function() {
    var layer = layui.layer,
        $ = layui.jquery,
        form = layui.form;
    form.on('submit(login)', function(data){
    	return false;
    });
});
var handlerPopup = function (captchaObj) {
    // 成功的回调
    captchaObj.onSuccess(function () {
        var validate = captchaObj.getValidate();
        console.log("sss")
        $.ajax({
            url: "/geetest/validate", // 进行二次验证
            type: "post",
            dataType: "json",
            data: {
                geetest_challenge: validate.geetest_challenge,
                geetest_validate: validate.geetest_validate,
                geetest_seccode: validate.geetest_seccode
            },
            success: function (data) {
            	$('#login_form').form('submit',{
            		url:'/system/login.do',
            		onSubmit:function(){
            			return $(this).form('enableValidation').form('validate');
            		},
            		 success: function (data) {
            				if(JSON.parse(data).status==200) {
           		     		document.location.href = "/container";
           		     	} else {
           		     		var number = parseInt(Math.random()*10);
           		     		if(number % 2 == 0) {
           		     			layer.tips(JSON.parse(data).msg,'#username');
           		     		} else {
           		     			layer.tips(JSON.parse(data).msg,'#password');
           		     		}
           		     	}
            		 }
            	});
            }
        });
        
    });
    $("#login-button").click(function () {
        captchaObj.show();
    });
    captchaObj.appendTo("#popup-captcha");
};
$.ajax({
    url: "/geetest/register?t=" + (new Date()).getTime(),
    type: "get",
    dataType: "json",
    success: function (data) {
        initGeetest({
            gt: data.gt,
            challenge: data.challenge,
            product: "popup", 
            offline: !data.success
        }, handlerPopup);
    }
});
</script>
</html>